<?php
declare (strict_types=1);

namespace app\exam\service\admin;

use app\common\service\BaseService;
use app\exam\logic\admin\PaperShareConfig as PaperShareConfigLogic;
use think\annotation\Inject;
use think\facade\Request;

/**
 * Class PaperShareConfig
 *
 * @package app\exam\service\admin
 */
class PaperShareConfig extends BaseService
{

    /**
     * @Inject()
     *
     * @var PaperShareConfigLogic
     */
    protected $paperShareConfigLogic;

    /**
     * set
     *
     * @param int $paperId
     * @return \think\Response
     * @throws \Yansongda\Pay\Exceptions\BusinessException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function set(int $paperId)
    {
        $cnfData = Request::post();

        unset($cnfData['paper_id']);

        $this->paperShareConfigLogic->saveConfig($paperId, $cnfData);

        return $this->parseToData([], 1, '设置成功');
    }

    /**
     * get
     *
     * @param int $paperId
     * @return \think\Response
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function get(int $paperId)
    {
        $data = $this->paperShareConfigLogic->get($paperId);

        return $this->parseToData($data, 1, '获取成功');
    }
}